from flask import Flask, render_template, request, jsonify, session, redirect, url_for, send_file
import os
import json
import zipfile
import shutil
from datetime import datetime
import uuid

app = Flask(__name__)
app.secret_key = 'your-secret-key-change-this'

# 配置
REPOSITORIES_DIR = 'repositories'
USERS_FILE = 'users.json'

# 确保目录存在
os.makedirs(REPOSITORIES_DIR, exist_ok=True)

# 初始化用户数据
if not os.path.exists(USERS_FILE):
    with open(USERS_FILE, 'w') as f:
        json.dump({}, f)

@app.route('/')
def index():
    if 'username' not in session:
        return redirect(url_for('login'))
    
    username = session['username']
    user_repos = []
    
    # 获取用户的仓库列表
    user_dir = os.path.join(REPOSITORIES_DIR, username)
    if os.path.exists(user_dir):
        for repo